package com.example.h1nson.realphotography.asyncTask;

import android.os.AsyncTask;

import com.example.h1nson.realphotography.config.ConfigURL;
import com.example.h1nson.realphotography.interface_photo.OnDataFinishedListener;
import com.example.h1nson.realphotography.util.HttpClientPost;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * Created by H1nson on 2016/6/16.
 */
public class CaptchaAsynTask extends AsyncTask<String, Integer, String> {
    private OnDataFinishedListener onDataFinishedListener;
    private JSONObject jsonObject;
    public CaptchaAsynTask(JSONObject json){
        jsonObject = json;


    }
    public void setOnDataFinishedListener(OnDataFinishedListener onDataFinishedListener){
        this.onDataFinishedListener = onDataFinishedListener;
    }
    @Override
    protected void onPostExecute(String s) {
        if(s!=null){
            onDataFinishedListener.onDataSuccessfully(s);

        }else
            onDataFinishedListener.onDataFailed();
        super.onPostExecute(s);
    }

    @Override
    protected String doInBackground(String... params) {
        String  jsonStr = jsonObject.toString();
        HttpClientPost post = new HttpClientPost(ConfigURL.captchaURL,jsonStr);
        post.doPost();
        return post.getJsonStrRes();
    }
}

